<%@ page language="java"  pageEncoding="UTF-8" %>
<%@ page import="com.shopping.modean.*" %>
<%@ page import="com.shopping.service.*" %>
<%@ page import="java.util.*" %>

<%
	Cart cart = (Cart)session.getAttribute("cart");
	
%>

<!DOCTYPE html>
<html>
<head>
  <title>购物车</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="script/regcheckdata.js"></script>
</head>

<body>
	<%
		if(cart == null) {
			cart = new Cart();
			out.println("购物车为空");
			return;
		} 
	%>
	
	<div style="text-align: center;">您一共购买了这么多商品：</div>
	<table border="1" align="center">
		<tr>
			<td>商品ID</td>
			<td>商品名称</td>
			<td>商品价格</td>
			<td>购买数量</td>
		</tr>
		<%
		  List<CartItem> items = cart.getItems();
		  for(CartItem item: items) {%>
			<tr>
				<td><%=item.getProductId() %></td>
				<td><%=ProductService.getInstance().detail(item.getProductId()).getDescr() %></td>
				<td><%=item.getPrice() %></td>
				<td><%=item.getCount() %></td>
			</tr>
		  <%}
		%>
		
	</table>
	<div style="text-align: center;">
	    <p>共<%=cart.getTotalPrice() %>元</p>
		<input type="button" value="修改数量" />
		<input type="button" value="确认购买" onclick="document.location.href='confirm.jsp'" />
		<input type="button" value="继续购买" onclick="document.location.href='index.jsp'">
	</div>
	
</body>
</html>